# -*- coding: utf-8 -*-
"""
Created on Fri Sep  7 20:44:31 2012

@author: xudi
barebones()"""

import numpy as np
import pylab as pl
'''source index'''
#t0=1.7e-15
#dt=t0/50
dt=8.3e-17
tc=4.2e-15
Dta=1.8e-15
'''fdtd index'''
space=500
mtnum=300
maxtime=mtnum*dt
ez=np.zeros(space)
hy=np.zeros(space-1)
dz=2.5e-8
e0=8.85e-12
u0=1.26e-6

def source(size):
    t=np.arange(0,1e-11,dt)
    ts=t[:size]
    ex=np.sin(2*np.pi*ts*0.6e15)*np.exp(-((ts-tc)/Dta)**2/2)
    #pl.plot(ts,ex)
    #pl.show()
    return ex


def fft(fftx,fft_size,sampling_rate):
    xf1=np.fft.fft(fftx,fft_size)
    xf2=np.abs(np.fft.fftshift(xf1))
    freqs=np.linspace(0,sampling_rate,fft_size)-sampling_rate/2
    t=np.arange(0,1e-10,dz)
    pl.figure(figsize=(8,6))
    pl.subplot(211)
    pl.plot(t[:fft_size],fftx)
    pl.subplot(212)
    pl.plot(freqs,xf2)
    pl.show()


def barebones():
    source1=source(mtnum)
    qtime=0
    count=0
    for qtime in range(0,mtnum):
        hy[0:space-1]=hy[0:space-1]+(ez[1:space]-ez[0:space-1])*(dt/u0)/dz
        ez[1:space-1]=ez[1:space-1]+(hy[1:space-1]-hy[0:space-2])*(dt/e0)/dz
        ez[0]=source1[qtime]
        if qtime%50==0:
            test=ez
            fft(test,space,1/dt)
        count+=1
        qtime+=1
    
    